<template>
  <div :id="id"  style="width: 100%;height:100%"></div>
</template>

<script>

const echarts = require('echarts/lib/echarts');
require('echarts/lib/component/title');
require('echarts/lib/component/tooltip');
require('echarts/lib/component/legend');
require('echarts/lib/chart/pie');

export default {
  props: ['id','title'],
  data(){
    return{
      dataList:[]
    }
  },
  mounted() {
    this.drawPie()
  },
  methods:{
    setDate(data){
      this.dataList=data;
      this.drawPie()
    },
    drawPie(){
      let chartDom = document.getElementById(this.id);
      let myChart = echarts.init(chartDom,'shine');
      let option = {
        title: {
          text: this.title,
          left: 'left'
        },
        tooltip: {
          trigger: 'item'
        },
        legend: {
          orient: 'vertical',
          left: 'right'
        },
        series: [
          {

            itemStyle: {
              normal: {
                label: {
                  show: true,
                  formatter: '{b} : {c} ({d}%)'
                },
                labelLine: {show: true}
              },
            },
            type: 'pie',
            radius: '50%',
            data:  this.dataList,
            color:["#5470c5","#ed6666"],
            emphasis: {
              itemStyle: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: 'rgba(0, 0, 0, 0.5)'
              }
            }
          }
        ]
      };
      myChart.setOption(option)
    }
  }
}
</script>

<style scoped>

</style>